﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Xml;

/// <summary>
/// Summary description for mtserver
/// </summary>
public class mtserver
{
    TUnit.Class.CLogin _login = null;

    public TUnit.Class.CLogin Login
    {
        get {
            return _login; }
        set { _login = value; }
    }
    string _action = "";

    public string Action
    {
        get { return _action; }
        set { _action = value; }
    }

    HttpContext _context = null;

    public HttpContext Context
    {
        get { return _context; }
        set { _context = value; }
    }

    public mtserver(TUnit.Class.CLogin login, HttpContext context)
	{
        this.Login = login;
        this.Context = context;
        this.Action = (context.Request.Params["action"] != null ? context.Request.Params["action"].ToString() : "");
	}
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public bool doAction()
    {
        try
        {
            switch (this.Action)
            {
                #region 
                case "SCGLINE":
                    {
                        this.Context.Response.Write("OK");
                        return true;
                    }
                    break;
                case "VVCLIP":
                    {
                        #region
                        string videoid = Context.Request.Params["videoid"].ToString();
                        viclip.CViClip ViClip = new viclip.CViClip(Login, videoid);
                        //string shtml = "<object width=\"120\" height=\"73\">";
                        //    shtml+= "<param name=\"movie\" value=\"http://www.youtube.com/watch?v=ZVYIBIlTIQs&feature=youtube_gdata\"></param>";
                        //    shtml+= "<param name=\"allowFullScreen\" value=\"true\"></param>";
                        //    shtml+= "<param name=\"allowscriptaccess\" value=\"always\"></param>";
                        //    shtml+= "<embed src=\"http://www.youtube.com/watch?v=ZVYIBIlTIQs&feature=youtube_gdata\" type=\"application/x-shockwave-flash\"";                         //    shtml+= "allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"120\" height=\"73\"></embed>";
                        //shtml+= "</object>";
                        //string shtml = "<embed id='clipid' src='{0}' type='application/x-shockwave-flash' width='100%' height='100%'></embed>";
                        //string shtml = "<iframe class=\"youtube-player\" type=\"text/html\" width=\"320\" height=\"480\" src=\"{0}\" frameborder=\"0\">";
                        //string shtml = "<iframe class='youtube-player' type='text/html' width='100%' height='100%' src='{0}&version=3' frameborder='0'>";
                        string shtml = "<html> <body> <embed src='{0}'; type=application/x-shockwave-flash width='98%' height='98%'> </embed> </body> </html>";
                        //string shtml = "<object width='100%' height='100%'><param name='movie' value='{0}'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src="http://www.youtube.com/watch?v=ZVYIBIlTIQs&feature=youtube_gdata" type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='120' height='73'></embed></object>
                        //string shtml = "<iframe class='youtube-player' type='text/html' width='100%' height='100%' src='http://www.youtube.com/embed/bIPcobKMB94'frameborder='0'>";
                        this.Context.Response.Write(String.Format(shtml, ViClip.linkvideo));
                        //this.Context.Response.Write(shtml);
                        ViClip.userviewer++;
                        return ViClip.Save();
                        #endregion
                    }
                    break;
                case "SEARCH":
                    {
                        #region search
                        string value = Context.Request.Params["value"].ToString();

                        int pagecount = 25;
                        if (Context.Request.Params["pagecount"] != null)
                            pagecount = Convert.ToInt32(Context.Request.Params["pagecount"]);
                        int pageindex = 0;
                        if (Context.Request.Params["pageindex"] != null)
                            pageindex = Convert.ToInt32(Context.Request.Params["pageindex"]);

                        using (viclip.AccDBViClip db = new viclip.AccDBViClip())
                        {
                            TUnit.Class.CCollection tmp = db.Search(Login, value);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            int count = 0;
                            for (int i = pageindex * pagecount; i < tmp.Count; i++)
                            {
                                if (count == pagecount)
                                    break;
                                count++;
                                viclip.CViClip obj = (viclip.CViClip)tmp[i];
                                xmlWriter.WriteStartElement("Video");
                                    //videoid
                                    xmlWriter.WriteStartElement("videoid");
                                    xmlWriter.WriteValue(obj.videoid.ToString());
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("videotitle");
                                    xmlWriter.WriteValue(obj.videotitle);
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("vote");
                                    xmlWriter.WriteValue((obj.userviewer > 100 ? "5" : (obj.userviewer > 80 ? "4" : (obj.userviewer > 50 ? "3" : "2"))));
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("description");
                                    xmlWriter.WriteValue(obj.description);
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("userviewer");
                                    xmlWriter.WriteValue(obj.userviewer.ToString());
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("timeupdate");
                                    xmlWriter.WriteValue(ToDisplayDateTime(obj.timeupdate));
                                    xmlWriter.WriteEndElement();

                                    //xmlWriter.WriteStartElement("userviewer");
                                    //xmlWriter.WriteValue(obj.linkvideo);
                                    //xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("logovideo");
                                    xmlWriter.WriteValue(obj.Logovideo);
                                    xmlWriter.WriteEndElement();
                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TOPVIEWS":
                    {
                        #region search

                        int pagecount = 25;
                        if (Context.Request.Params["pagecount"] != null)
                            pagecount = Convert.ToInt32(Context.Request.Params["pagecount"]);
                        int pageindex = 0;
                        if (Context.Request.Params["pageindex"] != null)
                            pageindex = Convert.ToInt32(Context.Request.Params["pageindex"]);

                        using (viclip.AccDBViClip db = new viclip.AccDBViClip())
                        {
                            TUnit.Class.CCollection tmp = db.SearchTopViewer(Login);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            int count = 0;
                            for (int i = pageindex * pagecount; i < tmp.Count; i++)
                            {
                                if (count == pagecount)
                                    break;
                                count++;
                                viclip.CViClip obj = (viclip.CViClip)tmp[i];
                                xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("videoid");
                                xmlWriter.WriteValue(obj.videoid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("videotitle");
                                xmlWriter.WriteValue(obj.videotitle);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue((obj.userviewer > 100 ? "5" : (obj.userviewer > 80 ? "4" : (obj.userviewer > 50 ? "3" : "2"))));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue(obj.description);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("userviewer");
                                xmlWriter.WriteValue(obj.userviewer.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("timeupdate");
                                xmlWriter.WriteValue(ToDisplayDateTime(obj.timeupdate));
                                xmlWriter.WriteEndElement();

                                //xmlWriter.WriteStartElement("userviewer");
                                //xmlWriter.WriteValue(obj.linkvideo);
                                //xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("logovideo");
                                xmlWriter.WriteValue(obj.Logovideo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "VUAHAIID":
                    {
                        string videoid = Context.Request.Params["videoid"].ToString();
                        viclip.CVideos ViClip = new viclip.CVideos(Login, videoid);
                        string shtml = "<html> <body> <embed src='{0}'; type=application/x-shockwave-flash width='88%' height='91%'> </embed> </body> </html>";
                        this.Context.Response.Write(String.Format(shtml, ViClip.linkvideo));
                        ViClip.userviews++;
                        return ViClip.Save();
                    }
                    break;
                case "CDENGLISHCHILDRENID":
                case "CDTOMANDJERRYID":
                case "CDENGLISH101ID":
                    {
                        string videoid = Context.Request.Params["videoid"].ToString();
                        viclip.CVideos ViClip = new viclip.CVideos(Login, videoid);
                        string shtml = "<html> <body> <embed src='{0}'; type=application/x-shockwave-flash width='98%' height='98%'> </embed> </body> </html>";
                        this.Context.Response.Write(String.Format(shtml, ViClip.linkvideo));
                        ViClip.userviews++;
                        return ViClip.Save();
                    }
                    break;
                case "CDENGLISH101":
                    {
                        #region search

                        //int pagecount = 25;
                        //if (Context.Request.Params["pagecount"] != null)
                        //    pagecount = Convert.ToInt32(Context.Request.Params["pagecount"]);
                        //int pageindex = 0;
                        //if (Context.Request.Params["pageindex"] != null)
                        //    pageindex = Convert.ToInt32(Context.Request.Params["pageindex"]);

                        using (viclip.AccDBVideos db = new viclip.AccDBVideos())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionCD101(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            //int count = 0;
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                //if (count == pagecount)
                                //    break;
                                //count++;
                                viclip.CVideos obj = (viclip.CVideos)tmp[i];
                                xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("videoid");
                                xmlWriter.WriteValue(obj.videoid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("videotitle");
                                xmlWriter.WriteValue(obj.videoTitle);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue((obj.userviews > 100 ? "5" : (obj.userviews > 80 ? "4" : (obj.userviews > 50 ? "3" : "2"))));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue(obj.description);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("userviewer");
                                xmlWriter.WriteValue(obj.userviews.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("timeupdate");
                                xmlWriter.WriteValue(ToDisplayDateTime(obj.timeupdate));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("logovideo");
                                xmlWriter.WriteValue(obj.logo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "CDTOMANDJERRY":
                    {
                        #region search
                        using (viclip.AccDBVideos db = new viclip.AccDBVideos())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionTomAndJerry(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CVideos obj = (viclip.CVideos)tmp[i];
                                xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("videoid");
                                xmlWriter.WriteValue(obj.videoid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("videotitle");
                                xmlWriter.WriteValue(obj.videoTitle);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue((obj.userviews > 100 ? "5" : (obj.userviews > 80 ? "4" : (obj.userviews > 50 ? "3" : "2"))));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue(obj.description);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("userviewer");
                                xmlWriter.WriteValue(obj.userviews.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("timeupdate");
                                xmlWriter.WriteValue(ToDisplayDateTime(obj.timeupdate));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("logovideo");
                                xmlWriter.WriteValue(obj.logo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "CDENGLISHCHILDREN":
                    {
                        #region search
                        using (viclip.AccDBVideos db = new viclip.AccDBVideos())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionCHILDREN(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CVideos obj = (viclip.CVideos)tmp[i];
                                xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("videoid");
                                xmlWriter.WriteValue(obj.videoid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("videotitle");
                                xmlWriter.WriteValue(obj.videoTitle);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue((obj.userviews > 100 ? "5" : (obj.userviews > 80 ? "4" : (obj.userviews > 50 ? "3" : "2"))));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue(obj.description);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("userviewer");
                                xmlWriter.WriteValue(obj.userviews.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("timeupdate");
                                xmlWriter.WriteValue(ToDisplayDateTime(obj.timeupdate));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("logovideo");
                                xmlWriter.WriteValue(obj.logo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TOPNEW":
                    {
                        #region search
                        using (viclip.AccDBVideos db = new viclip.AccDBVideos())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionTopNew(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CVideos obj = (viclip.CVideos)tmp[i];
                                xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("videoid");
                                xmlWriter.WriteValue(obj.videoid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("videotitle");
                                xmlWriter.WriteValue(obj.videoTitle);
                                xmlWriter.WriteEndElement();

                                //xmlWriter.WriteStartElement("vote");
                                //xmlWriter.WriteValue((obj.userviews > 100 ? "5" : (obj.userviews > 80 ? "4" : (obj.userviews > 50 ? "3" : "2"))));
                                //xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue(obj.description);
                                xmlWriter.WriteEndElement();

                                //xmlWriter.WriteStartElement("userviewer");
                                //xmlWriter.WriteValue(obj.userviews.ToString());
                                //xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("timeupdate");
                                xmlWriter.WriteValue(ToDisplayDateTime(obj.timeupdate));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("logovideo");
                                xmlWriter.WriteValue(obj.logo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("price");
                                xmlWriter.WriteValue(obj.Price);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TOPHOT":
                    {
                        #region search
                        using (viclip.AccDBVideos db = new viclip.AccDBVideos())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionTopHot(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CVideos obj = (viclip.CVideos)tmp[i];
                                xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("videoid");
                                xmlWriter.WriteValue(obj.videoid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("videotitle");
                                xmlWriter.WriteValue(obj.videoTitle);
                                xmlWriter.WriteEndElement();

                                //xmlWriter.WriteStartElement("vote");
                                //xmlWriter.WriteValue((obj.userviews > 100 ? "5" : (obj.userviews > 80 ? "4" : (obj.userviews > 50 ? "3" : "2"))));
                                //xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue(obj.description);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("userviewer");
                                xmlWriter.WriteValue(obj.userviews.ToString());
                                xmlWriter.WriteEndElement();

                                //xmlWriter.WriteStartElement("timeupdate");
                                //xmlWriter.WriteValue(ToDisplayDateTime(obj.timeupdate));
                                //xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("logovideo");
                                xmlWriter.WriteValue(obj.logo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("price");
                                xmlWriter.WriteValue(obj.Price);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "VIDEOLIST":
                    {
                        #region search
                        string catid = Context.Request.Params["catid"].ToString();
                        using (viclip.AccDBVideos db = new viclip.AccDBVideos())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionByCat(Login, tmp, catid);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CVideos obj = (viclip.CVideos)tmp[i];
                                xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("videoid");
                                xmlWriter.WriteValue(obj.videoid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("videotitle");
                                xmlWriter.WriteValue(obj.videoTitle);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue((obj.userviews > 100 ? "5" : (obj.userviews > 80 ? "4" : (obj.userviews > 50 ? "3" : "2"))));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue(obj.description);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("userviewer");
                                xmlWriter.WriteValue(obj.userviews.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("timeupdate");
                                xmlWriter.WriteValue(ToDisplayDateTime(obj.timeupdate));
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("logovideo");
                                xmlWriter.WriteValue(obj.logo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("price");
                                xmlWriter.WriteValue(obj.Price);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "CATHAI":
                    {
                        #region search
                        using (viclip.AccDBVideos db = new viclip.AccDBVideos())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionTomAndJerry(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            //-------------------------------------------------------
                            xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue("7");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue("Paris by Night");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue("Ca nhạc hài kịch");
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            //-------------------------------------------------------
                            //-------------------------------------------------------
                            xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue("15");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue("Hỏi xoáy đáp xoay");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue("Game show truyền hình");
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            //-------------------------------------------------------
                            //-------------------------------------------------------
                            xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue("13");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue("Hài xuân");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue("Tuyển tập hài xuân");
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            //-------------------------------------------------------
                            //-------------------------------------------------------
                            xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue("8");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue("Hài tổng hợp");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue("Tuyển chọn hài đặc sắc");
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            //-------------------------------------------------------
                            //-------------------------------------------------------
                            xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue("6");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue("Tom and Jerry");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue("Phim hoạt hình");
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            //-------------------------------------------------------
                            
                            //-------------------------------------------------------
                            xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue("14");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue("Vua hài đất Việt");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue("Game show truyền hình");
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            //-------------------------------------------------------
                            //-------------------------------------------------------
                            xmlWriter.WriteStartElement("Video");
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue("1");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue("Video Clip");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue("Tuyển chọn Clip hài");
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            //-------------------------------------------------------

                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "CATFILMS":
                    {
                        #region search
                        using (viclip.AccDBCatalogVideos db = new viclip.AccDBCatalogVideos())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionFilm(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CLIP");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            //-------------------------------------------------------
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                xmlWriter.WriteStartElement("Video");
                                viclip.CCatalogVideos obj = (viclip.CCatalogVideos)tmp[i];
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue(obj.catalogid);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue(obj.catalogname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("description");
                                xmlWriter.WriteValue("");
                                xmlWriter.WriteEndElement();
                                xmlWriter.WriteEndElement();
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                #endregion

                #region SDKU

                case "GMSDKULOGIN":
                    {
                        #region
                        string email = Context.Request.Params["email"].ToString();
                        string pass = Context.Request.Params["pass"].ToString();
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("azsoft");
                        xmlWriter.WriteStartElement("LOGIN");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");
                        viclip.CGMSdkuLogin acc = new viclip.CGMSdkuLogin(Login, email);
                        if (acc.password == pass)
                        {
                            xmlWriter.WriteValue("OK");
                        }
                        else
                        {
                            if (acc.email == email)
                            {
                                xmlWriter.WriteValue("ERPASS");
                            }
                            else
                            {
                                xmlWriter.WriteValue("EREMAIL");
                            }
                        }
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("memberid");
                        xmlWriter.WriteValue(acc.memberid);
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                    break;

                case "GMSDKUREGISTER":
                    {
                        #region
                        string email = Context.Request.Params["email"].ToString();
                        string pass = Context.Request.Params["pass"].ToString();
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("azsoft");
                        xmlWriter.WriteStartElement("REGISTER");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");
                        viclip.CGMSdkuLogin acc = new viclip.CGMSdkuLogin(Login);
                        if (acc.CheckKey("email", email, "tblGMSdkuLogin"))
                        {
                            xmlWriter.WriteValue("EREMAIL");
                        }
                        else
                        {
                            acc.email = email;
                            acc.password = pass;
                            if (acc.Save())
                            {
                                xmlWriter.WriteValue("OK");
                            }
                            else
                            {
                                xmlWriter.WriteValue("ER");
                            }
                        }
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                    break;

                case "GMSDKUS":
                    {
                        #region search
                        string memberid = Context.Request.Params["memberid"].ToString();
                        using (viclip.AccDBGMSdku db = new viclip.AccDBGMSdku())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("SUDOKU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            //-------------------------------------------------------
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CGMSdku obj = (viclip.CGMSdku)tmp[i];
                                if ((memberid == "0" && obj.sdkustatus != "OF") || obj.sdkustatus == "ON")
                                {
                                    xmlWriter.WriteStartElement("SDKU");
                                    //videoid
                                    xmlWriter.WriteStartElement("sdkuid");
                                    xmlWriter.WriteValue(obj.sdkuid);
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("sdkuname");
                                    xmlWriter.WriteValue(obj.sdkuname);
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("sdkutime");
                                    xmlWriter.WriteValue(obj.sdkutime.ToShortDateString());
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("sdkustatus");
                                    xmlWriter.WriteValue(obj.sdkustatus);
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteEndElement();
                                }
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;

                case "GMSDKU":
                    {
                        #region search
                        string sdkuid = Context.Request.Params["sdkuid"].ToString();
                        viclip.CGMSdku Sdku = new viclip.CGMSdku(Login, sdkuid);
                        if (Sdku.Cells != null)
                        {
                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("SUDOKU");
                            //-------------------------------------------------------
                            for (int i = 0; i < Sdku.Cells.Count; i++)
                            {
                                xmlWriter.WriteStartElement("cell");
                                viclip.CGMSdkuData obj = (viclip.CGMSdkuData)Sdku.Cells[i];
                                //videoid
                                xmlWriter.WriteStartElement("row");
                                xmlWriter.WriteValue(obj.row);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("col");
                                xmlWriter.WriteValue(obj.col);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("number");
                                xmlWriter.WriteValue(obj.number);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("readonly");
                                xmlWriter.WriteValue(obj.readOnly);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;

                case "GMSDKUSUBMIT":
                    {
                        #region
                        string memberid = Context.Request.Params["memberid"].ToString();
                        string sdkuid = Context.Request.Params["sdkuid"].ToString();
                        string mtime = Context.Request.Params["mtime"].ToString();
                        
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("azsoft");
                        xmlWriter.WriteStartElement("KQ");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");

                        viclip.CGMSdkuMember obj = new viclip.CGMSdkuMember(this.Login);
                        obj.sdkuid = Convert.ToInt32(sdkuid);
                        obj.memberid = Convert.ToInt32(memberid);
                        obj.yourtime = Convert.ToInt32(mtime);
                        obj.timeupdate = DateTime.Now;

                        if (obj.Save())
                            xmlWriter.WriteValue("OK");
                        else
                            xmlWriter.WriteValue("ER");

                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion        
                    }
                    break;

                case "GMSDKURANKING":
                    {
                        #region search
                        string memberid = Context.Request.Params["memberid"].ToString();

                        using (viclip.AccDBGMSdkuMember db = new viclip.AccDBGMSdkuMember())
                        {
                            System.Data.DataTable dtRank = db.GetRankingTopMember(Login);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("SUDOKU");

                            //xmlWriter.WriteStartElement("total");
                            //xmlWriter.WriteValue(tmp.Count.ToString());
                            //xmlWriter.WriteEndElement();

                            //-------------------------------------------------------
                            //for (int i = 0; i < tmp.Count; i++)
                            int i = 1;
                            foreach(System.Data.DataRow dr in dtRank.Rows)
                            {
                                if (i < 10 || dr["memberid"].ToString().Equals(memberid))
                                {
                                    xmlWriter.WriteStartElement("SDKU");

                                    xmlWriter.WriteStartElement("rank");
                                    xmlWriter.WriteValue(i.ToString());
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("memberid");
                                    xmlWriter.WriteValue(dr["memberid"].ToString());
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("mTime");
                                    xmlWriter.WriteValue(dr["mTime"].ToString());
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("nick");
                                    string email = dr["email"].ToString();

                                    if(email.IndexOf("@") > 0)
                                        email = email.Substring(0, email.IndexOf("@"));

                                    xmlWriter.WriteValue(email);
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("iCount");
                                    xmlWriter.WriteValue(dr["iCount"].ToString());
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteEndElement();
                                }
                                i++;
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;

                case "GMSDKUMAP":
                    {
                        #region
                        string memberid = Context.Request.Params["memberid"].ToString();
                        string sdkuid = Context.Request.Params["sdkuid"].ToString();
                        string data = Context.Request.Params["data"].ToString();

                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("azsoft");
                        xmlWriter.WriteStartElement("KQ");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");

                        viclip.CGMSdku obj = new viclip.CGMSdku(this.Login, sdkuid);
                        if (obj.sdkustatus == "NA")
                        {
                            if (viclip.AccDBGMSdkuData.Delete(Login, obj))
                            {
                                int i = 0;
                                while (i < data.Length)
                                {
                                    int row = Convert.ToInt32(data.Substring(i, 1));
                                    int col = Convert.ToInt32(data.Substring(i+1, 1));
                                    int number = Convert.ToInt32(data.Substring(i+2, 1));

                                    viclip.CGMSdkuData o = new viclip.CGMSdkuData(Login);
                                    o.sdkuid = Convert.ToInt32(sdkuid);
                                    o.row = row;
                                    o.col = col;
                                    o.number = number;
                                    o.readOnly = 1;
                                    o.Save();

                                    i += 3;
                                }
                                xmlWriter.WriteValue("OK");
                            }
                            else
                            {
                                xmlWriter.WriteValue("ER");
                            }
                        }
                        else
                        {
                            xmlWriter.WriteValue("ER");
                        }
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                    break;
                #endregion

                #region NA
                case "CATNAUAN":
                    {
                        #region search
                        using (viclip.AccDBNACategories db = new viclip.AccDBNACategories())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CAT");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            //-------------------------------------------------------
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                xmlWriter.WriteStartElement("LOAI");
                                viclip.CNACategories obj = (viclip.CNACategories)tmp[i];
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue(obj.CategoriesId);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue(obj.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("menuname");
                                xmlWriter.WriteValue(obj.DisplayMenuName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("menuid");
                                xmlWriter.WriteValue(obj.MenuItemIdTop);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;

                case "MNULIST":
                    {
                        #region search
                        string catid = Context.Request.Params["catid"].ToString();
                        using (viclip.AccDBNAMenuItem db = new viclip.AccDBNAMenuItem())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionByCat(Login, tmp, catid);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CNAMenuItem obj = (viclip.CNAMenuItem)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.menuitemid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.menuitemname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.menucaption);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("idvideo");
                                xmlWriter.WriteValue(obj.idvideo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TOPNEWMENU":
                    {
                        #region search
                        using (viclip.AccDBNAMenuItem db = new viclip.AccDBNAMenuItem())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CNAMenuItem obj = (viclip.CNAMenuItem)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.menuitemid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.menuitemname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.categories.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("idvideo");
                                xmlWriter.WriteValue(obj.idvideo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "NAYEUTHICH":
                    {
                        #region search
                        string memberid = Context.Request.Params["memberid"].ToString();

                        using (viclip.AccDBNAMenuItem db = new viclip.AccDBNAMenuItem())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionByMember(Login, tmp, memberid);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CNAMenuItem obj = (viclip.CNAMenuItem)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.menuitemid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.menuitemname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.menucaption);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("idvideo");
                                xmlWriter.WriteValue(obj.idvideo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "NASEARCH":
                    {
                        #region search
                        string svalue = Context.Request.Params["svalue"].ToString();
                        
                        using (viclip.AccDBNAMenuItem db = new viclip.AccDBNAMenuItem())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionSearch(Login, tmp, svalue);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CNAMenuItem obj = (viclip.CNAMenuItem)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.menuitemid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.menuitemname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.menucaption);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("idvideo");
                                xmlWriter.WriteValue(obj.idvideo);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "NALOGIN":
                    {
                        #region
                        string email = Context.Request.Params["email"].ToString();
                        string pass = Context.Request.Params["pass"].ToString();
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();
                        
                        xmlWriter.WriteStartElement("azsoft");
                        xmlWriter.WriteStartElement("LOGIN");
                            xmlWriter.WriteStartElement("RS");
                                xmlWriter.WriteStartElement("result");
                                viclip.CNALogin acc = new viclip.CNALogin(Login, email);
                                if (acc.password == pass)
                                {
                                    xmlWriter.WriteValue("OK");
                                }
                                else
                                {
                                    if (acc.email == email)
                                    {
                                        xmlWriter.WriteValue("ERPASS");
                                    }
                                    else
                                    {
                                        xmlWriter.WriteValue("EREMAIL");
                                    }
                                }
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("memberid");
                                xmlWriter.WriteValue(acc.memberid);
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        
                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                    break;
                case "NAREGISTER":
                    {
                        #region
                        string email = Context.Request.Params["email"].ToString();
                        string pass = Context.Request.Params["pass"].ToString();
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("azsoft");
                        xmlWriter.WriteStartElement("REGISTER");
                            xmlWriter.WriteStartElement("RS");
                                xmlWriter.WriteStartElement("result");
                                viclip.CNALogin acc = new viclip.CNALogin(Login);
                                if (acc.CheckKey("email", email, "tblNALogin"))
                                {
                                    xmlWriter.WriteValue("EREMAIL");
                                }
                                else
                                {
                                    acc.email = email;
                                    acc.password = pass;
                                    if (acc.Save())
                                    {
                                        xmlWriter.WriteValue("OK");
                                    }
                                    else
                                    {
                                        xmlWriter.WriteValue("ER");
                                    }
                                }
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                    break;
                case "NAMENUCONTENT":
                    {
                        #region
                        string menuid = Context.Request.Params["menuid"].ToString();

                        viclip.CNAMenuItem mnu = new viclip.CNAMenuItem(this.Login, menuid);
                        this.Context.Response.Write(mnu.descriptions);
                        return true;
                        #endregion
                    }
                    break;
                //Them vao muc yeu thich
                case "NAADDYT":
                    {
                        #region
                        string memberid = Context.Request.Params["memberid"].ToString();
                        string menuid = Context.Request.Params["menuid"].ToString();
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("KQ");
                                xmlWriter.WriteStartElement("RS");
                                    xmlWriter.WriteStartElement("result");

                                    viclip.CNAMnuYT obj = new viclip.CNAMnuYT(this.Login);
                                    obj.menuid = Convert.ToInt32(menuid);
                                    obj.memberid = Convert.ToInt32(memberid);
                                    if(obj.Save())
                                        xmlWriter.WriteValue("OK");
                                    else
                                        xmlWriter.WriteValue("ER");

                                    xmlWriter.WriteEndElement();
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                    break;
                case "NAVIDEO":
                    {
                        #region
                        string idvideo = Context.Request.Params["idvideo"].ToString();
                        string urlYouTube = "http://www.youtube.com/watch?v=" + idvideo;
                        string shtml = "<html> <body> <embed src='{0}'; type=application/x-shockwave-flash width='98%' height='98%'> </embed> </body> </html>";
                        this.Context.Response.Write(String.Format(shtml, urlYouTube));
                        return true;
                        #endregion
                    }
                    break;
                #endregion

                #region TRUYEN CUOI
                case "CATTRC":
                    {
                        #region search
                        using (viclip.AccDBTRCCategories db = new viclip.AccDBTRCCategories())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CAT");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            //-------------------------------------------------------
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                xmlWriter.WriteStartElement("LOAI");
                                viclip.CTRCCategories obj = (viclip.CTRCCategories)tmp[i];
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue(obj.CategoriesId);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue(obj.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("StoryName");
                                xmlWriter.WriteValue(obj.DisplayStoryName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("StoryId");
                                xmlWriter.WriteValue(obj.StoryIdTop);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;

                case "TRCLIST":
                    {
                        #region search
                        string catid = Context.Request.Params["catid"].ToString();
                        using (viclip.AccDBTRCStorys db = new viclip.AccDBTRCStorys())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionByCat(Login, tmp, catid);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CTRCStorys obj = (viclip.CTRCStorys)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.storyid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.storyname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.descriptions);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue(obj.vote);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TOPNEWTRC":
                    {
                        #region search
                        using (viclip.AccDBTRCStorys db = new viclip.AccDBTRCStorys())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CTRCStorys obj = (viclip.CTRCStorys)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.storyid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.storyname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.categories.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue(obj.vote);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TRCTOPHOT":
                    {
                        #region search
                        using (viclip.AccDBTRCStorys db = new viclip.AccDBTRCStorys())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CTRCStorys obj = (viclip.CTRCStorys)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.storyid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.storyname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.categories.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue(obj.vote);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TRCSEARCH":
                    {
                        #region search
                        string svalue = Context.Request.Params["svalue"].ToString();

                        using (viclip.AccDBTRCStorys db = new viclip.AccDBTRCStorys())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionSearch(Login, tmp, svalue);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CTRCStorys obj = (viclip.CTRCStorys)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.storyid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.storyname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.categories.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue(obj.vote);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TRCCONTENT":
                    {
                        #region
                        string storyid = Context.Request.Params["storyid"].ToString();

                        viclip.CTRCStorys mnu = new viclip.CTRCStorys(this.Login, storyid);
                        this.Context.Response.Write(mnu.storycontents);
                        return true;
                        #endregion
                    }
                    break;
                #endregion

                #region TRUYEN TRANH
                case "CATTR":
                    {
                        #region search
                        using (viclip.AccDBTRCategories db = new viclip.AccDBTRCategories())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CAT");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            //-------------------------------------------------------
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                xmlWriter.WriteStartElement("LOAI");
                                viclip.CTRCategories obj = (viclip.CTRCategories)tmp[i];
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue(obj.CategoriesId);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("cattitle");
                                xmlWriter.WriteValue(obj.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("StoryName");
                                xmlWriter.WriteValue(obj.DisplayStoryName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("StoryId");
                                xmlWriter.WriteValue(obj.StoryIdTop);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;

                case "TRLIST":
                    {
                        #region search
                        string catid = Context.Request.Params["catid"].ToString();
                        using (viclip.AccDBTRStorys db = new viclip.AccDBTRStorys())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionByCat(Login, tmp, catid);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CTRStorys obj = (viclip.CTRStorys)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.storyid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.storyname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue("");
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue(obj.vote);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TOPNEWTR":
                    {
                        #region search
                        using (viclip.AccDBTRStorys db = new viclip.AccDBTRStorys())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CTRStorys obj = (viclip.CTRStorys)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.storyid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.storyname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.categories.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue(obj.vote);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TRTOPHOT":
                    {
                        #region search
                        using (viclip.AccDBTRStorys db = new viclip.AccDBTRStorys())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CTRStorys obj = (viclip.CTRStorys)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.storyid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.storyname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.categories.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue(obj.vote);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TRSEARCH":
                    {
                        #region search
                        string svalue = Context.Request.Params["svalue"].ToString();

                        using (viclip.AccDBTRStorys db = new viclip.AccDBTRStorys())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionSearch(Login, tmp, svalue);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CTRStorys obj = (viclip.CTRStorys)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.storyid.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.storyname);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.categories.CategoriesName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("vote");
                                xmlWriter.WriteValue(obj.vote);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "TRCONTENT":
                    {
                        #region
                        string storyid = Context.Request.Params["storyid"].ToString();

                        viclip.CTRStorys mnu = new viclip.CTRStorys(this.Login, storyid);
                        this.Context.Response.Write(mnu.descripptions);
                        return true;
                        #endregion
                    }
                    break;
                #endregion

                #region FILM
                case "CATFILM":
                    {
                        #region search
                        using (viclip.AccDBFILMCategories db = new viclip.AccDBFILMCategories())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollection(Login, tmp);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("CAT");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            //-------------------------------------------------------
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                xmlWriter.WriteStartElement("LOAI");
                                viclip.CFILMCategories obj = (viclip.CFILMCategories)tmp[i];
                                //videoid
                                xmlWriter.WriteStartElement("catid");
                                xmlWriter.WriteValue(obj.FilmCategoriesId);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("catname");
                                xmlWriter.WriteValue(obj.DisplayMenuName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("display");
                                xmlWriter.WriteValue(obj.DisplayMenuName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.MenuItemIdTop);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                case "FILMLIST":
                    {
                        #region search
                        string catid = Context.Request.Params["catid"].ToString();
                        using (viclip.AccDBFILMTitles db = new viclip.AccDBFILMTitles())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionByCat(Login, tmp, catid);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("azsoft");
                            xmlWriter.WriteStartElement("MENU");

                            xmlWriter.WriteStartElement("total");
                            xmlWriter.WriteValue(tmp.Count.ToString());
                            xmlWriter.WriteEndElement();

                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CFILMTitles obj = (viclip.CFILMTitles)tmp[i];
                                xmlWriter.WriteStartElement("item");
                                //videoid
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.FilmTitleId.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("title");
                                xmlWriter.WriteValue(obj.FilmTitleName);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("des");
                                xmlWriter.WriteValue(obj.Descriptions);
                                xmlWriter.WriteEndElement();

                                //xmlWriter.WriteStartElement("idvideo");
                                //xmlWriter.WriteValue(obj.idvideo);
                                //xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                    break;
                #endregion

                #region Game Line
                case "LINES98":
                    {
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123adminazsoft;Persist Security Info=True;User ID = azgame_com_vn_db;Initial Catalog = azgame_com_vn_db;Data Source=112.213.89.156;";

                        string clientid = Context.Request.Params["clientid"].ToString();

                        viclip.CScoreGame gme = new viclip.CScoreGame(Login, clientid);
                        if (gme.userid == -1)
                            gme.Save();

                        this.Context.Response.Write(gme.userid.ToString());
                        return true;
                    }
                case "PAYCARD":
                    {
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123adminazsoft;Persist Security Info=True;User ID = azgame_com_vn_db;Initial Catalog = azgame_com_vn_db;Data Source=112.213.89.156;";
                        //this.Context.Response.Write("1");
                        //return true;
                        string cardNo = Context.Request.Params["cardNo"].ToString();
                        string seriNo = Context.Request.Params["seriNo"].ToString();
                        string telco = Context.Request.Params["telco"].ToString();

                        libviclip.ihb.ServiceControllerService pay = new libviclip.ihb.ServiceControllerService();
                        libviclip.ihb.LoginInput loginInput = new libviclip.ihb.LoginInput();
                        loginInput.web_code = "cVmaQwR8WWK";
                        loginInput.web_name = "tatuanvn_app";

                        libviclip.ihb.LoginOutput loginOutput = pay.login(loginInput);
                        if (loginOutput.status == "1")
                        {
                            ///this.Context.Response.Write("session_id:" + loginOutput.session_id + " status:" + loginOutput.status);
                            libviclip.ihb.CardChargingInput cCardChargingInput = new libviclip.ihb.CardChargingInput();
                            cCardChargingInput.web_name = "tatuanvn_app";
                            cCardChargingInput.session_id = loginOutput.session_id;
                            cCardChargingInput.card_code = seriNo + ":" + cardNo + "::" + (telco == "1" ? "VTT" : "VMS");

                            libviclip.ihb.CardChargingOutput cCardChargingOutput = pay.cardCharging(cCardChargingInput);
                            if (cCardChargingOutput.status == "1")
                            {
                                //thanh cong
                                this.Context.Response.Write("1");
                            }
                            else
                            {
                                //that bai
                                this.Context.Response.Write("0");
                            }

                            libviclip.ihb.LogoutInput logoutInput = new libviclip.ihb.LogoutInput();
                            logoutInput.web_code = "cVmaQwR8WWK";
                            logoutInput.web_name = "tatuanvn_app";
                            logoutInput.session_id = loginOutput.session_id;

                            libviclip.ihb.LogoutOutput logoutOutput = pay.logout(logoutInput);


                            viclip.CPayCards cardSave = new viclip.CPayCards(Login);
                            cardSave.cardno = cardNo;
                            cardSave.serino = seriNo;
                            cardSave.session_id = loginOutput.session_id;
                            cardSave.price = Convert.ToInt32(cCardChargingOutput.amount);
                            cardSave.status = cCardChargingOutput.status;
                            cardSave.telco = (telco == "1" ? "VTT" : "VMS");
                            cardSave.Save();
                            return true;
                        }
                        else
                        {
                            libviclip.ihb.LogoutInput logoutInput = new libviclip.ihb.LogoutInput();
                            logoutInput.web_code = "cVmaQwR8WWK";
                            logoutInput.web_name = "tatuanvn_app";
                            logoutInput.session_id = loginOutput.session_id;

                            libviclip.ihb.LogoutOutput logoutOutput = pay.logout(logoutInput);

                            this.Context.Response.Write("0");
                            return true;
                        }
                    }
                    break;
                #endregion

                #region WINE
                case "GSTORES":
                        {
                            Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@mmap;Persist Security Info=True;User ID = mmap;Initial Catalog = dbwines;Data Source=115.84.178.179;";

                            using (mywine.Class.AccDBStore db = new mywine.Class.AccDBStore())
                            {
                                //TUnit.Class.CLogin login = Login;

                                TUnit.Class.CCollection list = new TUnit.Class.CCollection();
                                db.GetCollection(Login, list);
                                if (list != null)
                                {
                                    Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                                    Context.Response.Write(mywine.Class.CStore.toString(list));
                                }
                                else
                                {
                                    Context.Response.Write("NULL");
                                }
                            }
                            return true;
                        }
                    case "GWCOLORS":
                        {
                            Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@mmap;Persist Security Info=True;User ID = mmap;Initial Catalog = dbwines;Data Source=115.84.178.179;";

                            string storeid = Context.Request.Params["storeid"].ToString();
                            mywine.Class.CStore obj = new mywine.Class.CStore(Login, Convert.ToInt32(storeid));
                            Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                            Context.Response.Write(mywine.Class.CWineColor.toString(obj.Collection));
                            return true;
                        }
                        break;
                    case "GSTYPES":
                        {
                            Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@mmap;Persist Security Info=True;User ID = mmap;Initial Catalog = dbwines;Data Source=115.84.178.179;";

                            string storeid = Context.Request.Params["storeid"].ToString();
                            string wtcolorid = Context.Request.Params["wtcolorid"].ToString();

                            if (wtcolorid != "-1")
                            {
                                mywine.Class.CWineColor obj = new mywine.Class.CWineColor(Login, wtcolorid);
                                Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                                Context.Response.Write(mywine.Class.CWCTypes.toString(obj.Collection));
                            }
                            else
                            {
                                mywine.Class.CWineColor obj = new mywine.Class.CWineColor(Login);
                                obj.storeid = Convert.ToInt32(storeid);
                                Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                                Context.Response.Write(mywine.Class.CWCTypes.toString(obj.Collection));
                            }
                            return true;
                        }
                    case "GWINES":
                        {
                            Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@mmap;Persist Security Info=True;User ID = mmap;Initial Catalog = dbwines;Data Source=115.84.178.179;";

                            string storeid = Context.Request.Params["storeid"].ToString();
                            string wtcolorid = Context.Request.Params["wtcolorid"].ToString();
                            string typeid = Context.Request.Params["typeid"].ToString();
                            string pricerange = Context.Request.Params["pricerange"].ToString();
                            mywine.Class.CWCTypes obj = new mywine.Class.CWCTypes(Login, Convert.ToInt32(typeid), Convert.ToInt32(wtcolorid));
                            obj.typeid = Convert.ToInt32(typeid);
                            obj.winecolorid = Convert.ToInt32(wtcolorid);
                            obj.Tag = storeid;
                            //pricerange = {UN7, F7T15, F15T25, OV25, ALL};
                            Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                            Context.Response.Write(mywine.Class.CWine.toString(obj.Collection, pricerange));
                            return true;
                        }
                    case "GWINESRATEIT":
                        {
                            Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@mmap;Persist Security Info=True;User ID = mmap;Initial Catalog = dbwines;Data Source=115.84.178.179;";

                            string wtcolorid = Context.Request.Params["wtcolorid"].ToString();
                            string typeid = Context.Request.Params["typeid"].ToString();
                            string pricerange = Context.Request.Params["pricerange"].ToString();
                            mywine.Class.CWCTypes obj = new mywine.Class.CWCTypes(Login, Convert.ToInt32(typeid), Convert.ToInt32(wtcolorid));
                            //pricerange = {UN7, F7T15, F15T25, OV25, ALL};
                            Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                            Context.Response.Write(mywine.Class.CWine.toString(obj.CollectionRate, pricerange));
                            return true;
                        }
                        break;
                    case "GWINEDEATAIL":
                        {
                            Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@mmap;Persist Security Info=True;User ID = mmap;Initial Catalog = dbwines;Data Source=115.84.178.179;";

                            string wineid = Context.Request.Params["wineid"].ToString();
                            mywine.Class.CWine obj = new mywine.Class.CWine(Login, Convert.ToInt32(wineid));
                            //pricerange = {UN7, F7T15, F15T25, OV25, ALL};
                            Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                            Context.Response.Write(obj.Description);
                            return true;
                        }
                    case "YOURSCORE":
                        {
                            Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@mmap;Persist Security Info=True;User ID = mmap;Initial Catalog = dbwines;Data Source=115.84.178.179;";

                            string wineid = Context.Request.Params["wineid"].ToString();
                            mywine.Class.CWine obj = new mywine.Class.CWine(Login, Convert.ToInt32(wineid));
                            //pricerange = {UN7, F7T15, F15T25, OV25, ALL};
                            Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                            Context.Response.Write("OK");
                            return true;
                        }
                    case "RATEIT":
                        {
                            Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@mmap;Persist Security Info=True;User ID = mmap;Initial Catalog = dbwines;Data Source=115.84.178.179;";

                            string wineid = Context.Request.Params["wineid"].ToString();
                            mywine.Class.CWine obj = new mywine.Class.CWine(Login, Convert.ToInt32(wineid));
                            //pricerange = {UN7, F7T15, F15T25, OV25, ALL};
                            Context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                            Context.Response.Write("OK");
                            return true;
                        }
                #endregion

                #region OLP
                case "ADDSVOLPA":
                    {
                        this.Context.Response.Write("http://www.azsoft.com.vn/myapp/nauan");
                        return true;
                    }
                case "OLPASIGNIN":
                    {
                        #region
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@olympia;Persist Security Info=True;User ID = azgame;Initial Catalog = azgame_olympia_com_vn;Data Source=112.213.89.156;";

                        string email = Context.Request.Params["email"].ToString();
                        string pass = Context.Request.Params["pass"].ToString();
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                            xmlWriter.WriteStartElement("azsoft");
                                xmlWriter.WriteStartElement("LOGIN");
                                    xmlWriter.WriteStartElement("RS");
                                        xmlWriter.WriteStartElement("result");
                                            viclip.CAccount acc = new viclip.CAccount(Login, email);
                                            if (acc.password == pass)
                                            {
                                                xmlWriter.WriteValue("OK");
                                            }
                                            else
                                            {
                                                if (acc.email == email)
                                                {
                                                    xmlWriter.WriteValue("ERPASS");
                                                }
                                                else
                                                {
                                                    xmlWriter.WriteValue("EREMAIL");
                                                }
                                            }
                                        xmlWriter.WriteEndElement();

                                        xmlWriter.WriteStartElement("fullname");
                                            xmlWriter.WriteValue(acc.fullname);
                                        xmlWriter.WriteEndElement();

                                        xmlWriter.WriteStartElement("score");
                                            xmlWriter.WriteValue(acc.AccLevelCurrent.score);
                                        xmlWriter.WriteEndElement();

                                        xmlWriter.WriteStartElement("retest");
                                            xmlWriter.WriteValue(acc.AccLevelCurrent.retest);
                                        xmlWriter.WriteEndElement();
                                        
                                        xmlWriter.WriteStartElement("level");
                                            xmlWriter.WriteValue(acc.GameLevelCurrent.gameLevelName);
                                        xmlWriter.WriteEndElement();

                                        xmlWriter.WriteStartElement("order");
                                            xmlWriter.WriteValue(acc.AccountOrder);
                                        xmlWriter.WriteEndElement();

                                    xmlWriter.WriteEndElement();
                                xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                case "OLPASIGNUP":
                    {
                        #region
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@olympia;Persist Security Info=True;User ID = azgame;Initial Catalog = azgame_olympia_com_vn;Data Source=112.213.89.156;";
                        string fullname = Context.Request.Params["fullname"].ToString();
                        string email = Context.Request.Params["email"].ToString();
                        string pass = Context.Request.Params["pass"].ToString();
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("azsoft");
                        xmlWriter.WriteStartElement("REGISTER");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");
                        viclip.CAccount acc = new viclip.CAccount(Login);
                        if (acc.CheckKey("email", email, "tblAccounts"))
                        {
                            xmlWriter.WriteValue("EREMAIL");
                        }
                        else
                        {
                            acc.fullname = fullname;
                            acc.email = email;
                            acc.password = pass;
                            if (acc.Save())
                            {
                                acc.AccLevelCurrent = new viclip.CAccLevel(Login);
                                acc.AccLevelCurrent.email = email;
                                acc.AccLevelCurrent.gameLevel = new viclip.CGameLevels(Login, 0);
                                acc.AccLevelCurrent.score = 0;
                                acc.AccLevelCurrent.retest = 0;
                                acc.AccLevelCurrent.Save();

                                xmlWriter.WriteValue("OK");
                            }
                            else
                            {
                                xmlWriter.WriteValue("ER");
                            }
                        }
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                case "OLPAQUEST":
                    {
                        #region search
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@olympia;Persist Security Info=True;User ID = azgame;Initial Catalog = azgame_olympia_com_vn;Data Source=112.213.89.156;";
                        string email = Context.Request.Params["email"].ToString();
                        using (viclip.AccDBNAMenuItem db = new viclip.AccDBNAMenuItem())
                        {
                            TUnit.Class.CCollection tmp = new TUnit.Class.CCollection();
                            db.GetCollectionByCat(Login, tmp, email);

                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("AZSOFT");
                            xmlWriter.WriteStartElement("PACKAGE");

                            xmlWriter.WriteStartElement("KHOIDONG");
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CQuestion obj = (viclip.CQuestion)tmp[i];
                                xmlWriter.WriteStartElement("question");
                                
                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.questionsId.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("content");
                                xmlWriter.WriteValue(obj.contents);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("answers");
                                xmlWriter.WriteValue(obj.answerA);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("answersAB");
                                xmlWriter.WriteValue(obj.answerCorrect);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();

                            xmlWriter.WriteStartElement("VCNV");
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CQuestion obj = (viclip.CQuestion)tmp[i];
                                xmlWriter.WriteStartElement("question");

                                xmlWriter.WriteStartElement("id");
                                xmlWriter.WriteValue(obj.questionsId.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("words");
                                xmlWriter.WriteValue(obj.contents);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("keyindex");
                                xmlWriter.WriteValue(obj.answerA);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("content");
                                xmlWriter.WriteValue(obj.answerCorrect);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();

                            xmlWriter.WriteStartElement("TANGTOC");
                            for (int i = 0; i < tmp.Count; i++)
                            {
                                viclip.CQuestion obj = (viclip.CQuestion)tmp[i];
                                xmlWriter.WriteStartElement("question");

                                xmlWriter.WriteStartElement("questionId");
                                xmlWriter.WriteValue(obj.questionsId.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("content");
                                xmlWriter.WriteValue(obj.contents);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("answers");
                                xmlWriter.WriteValue(obj.answerA);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("answersABCD");
                                xmlWriter.WriteValue(obj.answerCorrect);
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteStartElement("questionType");
                                xmlWriter.WriteValue(obj.questionsTypeId.ToString());
                                xmlWriter.WriteEndElement();

                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();

                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        #endregion
                    }
                case "OLPASUBMIT":
                    {
                        #region
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@olympia;Persist Security Info=True;User ID = azgame;Initial Catalog = azgame_olympia_com_vn;Data Source=112.213.89.156;";
                        string memberid = Context.Request.Params["questionid"].ToString();
                        string times = Context.Request.Params["times"].ToString();
                        string email = Context.Request.Params["email"].ToString();
                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("azsoft");
                        xmlWriter.WriteStartElement("KQ");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");

                        viclip.CNAMnuYT obj = new viclip.CNAMnuYT(this.Login);

                        if (obj.Save())
                            xmlWriter.WriteValue("OK");
                        else
                            xmlWriter.WriteValue("ER");

                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                case "OLPASTART":
                    {
                        #region
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@olympia;Persist Security Info=True;User ID = azgame;Initial Catalog = azgame_olympia_com_vn;Data Source=112.213.89.156;";
                        string email = Context.Request.Params["email"].ToString();

                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("AZSOFT");
                        xmlWriter.WriteStartElement("KQ");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");

                        viclip.CAccount obj = new viclip.CAccount(this.Login, email);

                        if (obj.AccLevelCurrent != null)
                        {
                            obj.AccLevelCurrent.retest+= 1;
                            if (obj.AccLevelCurrent.Save())
                                xmlWriter.WriteValue("OK");
                            else
                                xmlWriter.WriteValue("ER");
                        }else
                            xmlWriter.WriteValue("ER");

                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                case "OLPAUPSCORE":
                    {
                        #region
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@olympia;Persist Security Info=True;User ID = azgame;Initial Catalog = azgame_olympia_com_vn;Data Source=112.213.89.156;";
                        string email = Context.Request.Params["email"].ToString();
                        string score = Context.Request.Params["score"].ToString();

                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("AZSOFT");
                        xmlWriter.WriteStartElement("KQ");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");

                        viclip.CAccount obj = new viclip.CAccount(this.Login, email);

                        if (obj.AccLevelCurrent != null)
                        {
                            obj.AccLevelCurrent.score = Convert.ToInt32(score);
                            if (obj.AccLevelCurrent.Save())
                                xmlWriter.WriteValue("OK");
                            else
                                xmlWriter.WriteValue("ER");
                        }
                        else
                            xmlWriter.WriteValue("ER");

                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
               case "OLPARESET":
                    {
                        #region
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@olympia;Persist Security Info=True;User ID = azgame;Initial Catalog = azgame_olympia_com_vn;Data Source=112.213.89.156;";
                        string email = Context.Request.Params["email"].ToString();
                        string reset = Context.Request.Params["reset"].ToString();

                        this.Context.Response.Clear();
                        this.Context.Response.ContentType = "text/xml";
                        this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("AZSOFT");
                        xmlWriter.WriteStartElement("KQ");
                        xmlWriter.WriteStartElement("RS");
                        xmlWriter.WriteStartElement("result");

                        viclip.CAccount acc = new viclip.CAccount(this.Login, email);

                        if (acc.AccLevelCurrent != null)
                        {
                            if (reset == "ALL")
                            {
                                if (viclip.AccDBAccLevel.ResetAll(Login, email))
                                {
                                    acc.AccLevelCurrent = new viclip.CAccLevel(Login);
                                    acc.AccLevelCurrent.email = email;
                                    acc.AccLevelCurrent.gameLevel = new viclip.CGameLevels(Login, 0);
                                    acc.AccLevelCurrent.score = 0;
                                    acc.AccLevelCurrent.retest = 0;
                                    acc.AccLevelCurrent.Save();
                                    xmlWriter.WriteValue("OK");
                                }
                                else
                                    xmlWriter.WriteValue("ER");
                            }
                            else
                            {
                                acc.AccLevelCurrent.retest = 0;
                                acc.AccLevelCurrent.score = 0;
                                if (acc.AccLevelCurrent.Save())
                                    xmlWriter.WriteValue("OK");
                                else
                                    xmlWriter.WriteValue("ER");
                            }
                        }
                        else
                            xmlWriter.WriteValue("ER");

                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        System.IO.StreamReader reader;
                        stream.Position = 0;
                        reader = new System.IO.StreamReader(stream);
                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());
                        this.Context.Response.BinaryWrite(bytes);
                        return true;
                        #endregion
                    }
                case "OLPATOP"://http://localhost:2859/server/server.ashx?action=OLPATOP&email=tatuanvn@gmail.com
                    {
                        #region search
                        Login.Connectionstring = "Provider=SQLOLEDB.1;Password = 123@olympia;Persist Security Info=True;User ID = azgame;Initial Catalog = azgame_olympia_com_vn;Data Source=112.213.89.156;";

                        string email = Context.Request.Params["email"].ToString();
                        viclip.CAccount ac = new viclip.CAccount(Login, email);
                        if (ac.GameLevelCurrent != null)
                        {
                            this.Context.Response.Clear();
                            this.Context.Response.ContentType = "text/xml";
                            this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                            xmlWriter.WriteStartDocument();
                            xmlWriter.WriteStartElement("AZSOFT");
                            xmlWriter.WriteStartElement("OLPA");
                            //-------------------------------------------------------
                            for (int i = 0; i < ac.TopAccounts.Count; i++)
                            {
                                if (i < 10)
                                {
                                    viclip.CAccount a = (viclip.CAccount)ac.TopAccounts[i];

                                    xmlWriter.WriteStartElement("item");

                                    xmlWriter.WriteStartElement("fullname");
                                    xmlWriter.WriteValue(a.fullname);
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteStartElement("email");
                                    xmlWriter.WriteValue(a.email);
                                    xmlWriter.WriteEndElement();

                                    xmlWriter.WriteEndElement();
                                }
                            }
                            //-------------------------------------------------------
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndDocument();
                            xmlWriter.Flush();

                            System.IO.StreamReader reader;
                            stream.Position = 0;

                            reader = new System.IO.StreamReader(stream);

                            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd());

                            //write to response stream
                            this.Context.Response.BinaryWrite(bytes);
                            //this.Context.Response.End();
                            return true;
                        }
                        break;
                        #endregion
                    }
                #endregion
             }
        }
        catch(Exception e)
        {
            this.Context.Response.Write("ER");
        }
        return false;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="dtime"></param>
    /// <returns></returns>
    public string ToDisplayDateTime(DateTime dtime)
    {
        System.Globalization.DateTimeFormatInfo provider = new System.Globalization.DateTimeFormatInfo();
        provider.AMDesignator = "S\x00e1ng";
        provider.PMDesignator = "Chi\u1ec1u";
        provider.TimeSeparator = ":";
        provider.DateSeparator = "/";
        return dtime.ToString("HH:mm dd/MM/yyyy", provider);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public string ToSqlDateTime(DateTime value)
    {
        string text = string.Concat(new object[] { "'", value.Year, "-", value.Month, "-", value.Day, " ", value.Hour, ":", value.Minute, ":", value.Second, "'" });
        return (" CONVERT(DATETIME," + text + ",102) ");
    }
}
